package ControllerView

import FilesGenerator.ProjectGenerator
import com.trolltech.qt.gui.QMessageBox
import View.{AboutHelpView, WelcomeWindow}

/**
 * Created by IntelliJ IDEA.
 * User: danymorard
 * Date: 24.04.11
 * Time: 16:23
 * To change this template use File | Settings | File Templates.
 */

class ControllerApplication extends ControllerView {


  /**
   * create the welcome view
   */
  var welcomeView = new WelcomeWindow(this, null)
  welcomeView.show

  /**
   * Controller to manage the welcome view
   */
  // var controllerWelcomeView = new ControllerWelcomeView
  // controllerWelcomeView.welcomeView.show


  /**
   * View for creating a new project
   */
  var controllerNewProject: ControllerCreateProjectView = _

  /**
   * View for the tools
   */
  var controllerTools: ControllerToolsView = _

  /**
   * About view
   */
  var helpAboutView: AboutHelpView = _


  /**
   * method to connect different signal for this class
   */
  private def connectSignals {
    /*
  // connect the button cancel from the new project view to this class
  controllerWelcomeView.controllerNewProject.createProjectWindow.buttonCancel.clicked.connect(this, "newProjectButtonCancel()")

  // connect the button finish from the new project view to this class
  controllerWelcomeView.controllerNewProject.endCreationProject.connect(this, "endCreationProject()")

  // connect the button cancel from the tools view to tis class
  controllerWelcomeView.controllerTools.toolsWindow.buttonCancel.clicked.connect(this, "toolsViewButtonCancel()")

  // connect the button cancel from the tools view to tis class
  controllerWelcomeView.controllerTools.toolsWindow.buttonOkay.clicked.connect(this, "toolsViewButtonOk()") */
  }


  /**
   * this method is called when the user push on the button cancel of the new project window
   */
  def newProjectButtonCancel() {

    // show the welcome view
    welcomeView.show

    // hide the project window
    controllerNewProject.createProjectWindow.close
  }


  /**
   *  this method is called when the user finish to create the project
   */
  def endCreationProject() {

    /**
     * create the project with ProjectGenerator
     */
    ProjectGenerator.createStructure



    //
    QMessageBox.information(null, new String("Successfull"), new String("Your project was successfully created\n\nuse this commande in project folder to do actions" +
      "\nant scala-compile : compile all project\nant install : install apk into online device\nant clean : clean project\nant release : sign apk to market ant install it into online device"))


    // close the window for creating the new project
    controllerNewProject.createProjectWindow.close


    /**
     * Controller hte manage the main Window
     */
    System.exit(0)
  }


  /**
   * this method is called when the button cancel of the tools view is pushed
   */
  def toolsViewButtonCancel() {

    // close the tools view
    controllerTools.toolsWindow.close

    // display the main window
    welcomeView.show
  }


  /**
   * this method is called when the button okay of the tools view is pushed
   */
  def toolsViewButtonOk() {

    // close the tools view
     controllerTools.toolsWindow.close

    // display the main window
     welcomeView.show

  }

  /**
   *
   */
  def newProjectButtonClicked() {

    controllerNewProject = new ControllerCreateProjectView
    controllerNewProject.initView


    // connect the button cancel from the new project view to this class
    controllerNewProject.createProjectWindow.buttonCancel.clicked.connect(this, "newProjectButtonCancel()")

    // connect the button finish from the new project view to this class
    controllerNewProject.endCreationProject.connect(this, "endCreationProject()")


    welcomeView.hide
  }


  /**
   *
   */
  def toolsButtonClicked() {

    welcomeView.hide

    controllerTools = new ControllerToolsView
    controllerTools.toolsWindow.show


    controllerTools.keyActionButtonPressed

    // connect the button cancel from the tools view to tis class
    controllerTools.toolsWindow.buttonCancel.clicked.connect(this, "toolsViewButtonCancel()")

    // connect the button cancel from the tools view to tis class
    controllerTools.toolsWindow.buttonOkay.clicked.connect(this, "toolsViewButtonOk()")


  }


  /**
   *
   */
  def helpButtonClicked() = {


     helpAboutView = new AboutHelpView (null,null)

  }

}